<?php
namespace app\admin\model;
use think\Model;
class Log extends Model
{
	public function log($operation,$user=''){
        $log = model('Log');
        $list = [
            'username' => $user,
            'operation' => $operation,
            'time' => time(),
            'ip' => request()->ip()
        ];
		if($user==''){
			$list['username'] = session('username');
		}else{
			$user == '';
		}
        $log->save($list);
    }
	
	public function logdel($time){
		$log = model('Log');
		$time = input('time');
		if($time==7){
			$deltime = time() - 3600*24*7;
			Log::where('time','>',$deltime)->delete();
		}elseif($time==30){
			$deltime = time() - 3600*24*30;
			Log::where('time','>',$deltime)->delete();
		}elseif($time==0){
			Log::where('time','<',time())->delete();
		}
	}

}
